﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace HidesaburoDotNET.Core.AI
{
    public class Human : AbstractAI
    {
        static Mutex mutex = new Mutex();

        public event EventHandler DiscardEvent;

        public Human() { }


        public override void OnPlayerSet(Player player)
        {

        }

        public override bool DecideFinish(CompleteEventArgs args)
        {
            return false;
        }

        public override Hai SelectDiscard()
        {
            discard = null;

            if (DiscardEvent != null)
            {
                DiscardEvent(player, new EventArgs());
            }
            

            return discard;
        }
        Hai discard;

        public Hai Discard
        {
            get { return discard; }
            set {
                mutex.WaitOne();
                discard = value;
                mutex.ReleaseMutex();
            }
        }
        

        public void SelectDiscardThread()
        {
            while (true)
            {
                mutex.WaitOne();
                if (discard != null)
                {
                    mutex.ReleaseMutex();
                    return;
                }
            }
        }


        public override NakiAction CheckAction(Player sender, Hai discard)
        {
            return NakiAction.None;
        }

        public override object Clone()
        {
            return this;
        }
    }
}
